<?php
Loader::loadClass('ObjectUtilEx', "modules/VoteThailandPoll/pnincludes");
Loader::loadClass('DateUtilEx', "modules/VoteThailandPoll/pnincludes");
Loader::loadClass('PNObjectEx', "modules/VoteThailandPoll/pnincludes");
Loader::loadClass('PNObjectExArray', "modules/VoteThailandPoll/pnincludes");
Loader::loadClass('DBUtilEx', "modules/VoteThailandPoll/pnincludes");
Loader::loadClass('InnoUtil', "modules/VoteThailandPoll/pnincludes");

function VoteThailandPoll_pntables()
{
    // Initialise table array
    $pntable = array();

    ////////////////////////////////////////////
    //Province table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_province'] = DBUtil::getLimitedTablename('votethailandpoll_province');
    $pntable['votethailandpoll_province_column'] = array(
                                        'id'                => 'pro_id',
                                        'name'              => 'pro_name',
                                        'latitude'          => 'pro_latitude',
                                        'longitude'         => 'pro_longitude'
    );
    $pntable['votethailandpoll_province_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votethailandpoll_province_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_province_column'], 'pro_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_province_column_def']);

    ////////////////////////////////////////////
    //District table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_district'] = DBUtil::getLimitedTablename('votethailandpoll_district');
    $pntable['votethailandpoll_district_column'] = array(
                                        'id'                => 'dis_id',
                                        'pro_id'            => 'dis_pro_id',
                                        'name'              => 'dis_name',
                                        'latitude'          => 'dis_latitude',
                                        'longitude'         => 'dis_longitude'
    );
    $pntable['votethailandpoll_district_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votethailandpoll_district_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_district_column'], 'dis_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_district_column_def']);

    $pntable['votethailandpoll_district_column_idx'] = array('idx_dis_pro_id' => 'pro_id');

    ////////////////////////////////////////////
    //Tambon table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_tambon'] = DBUtil::getLimitedTablename('votethailandpoll_tambon');
    $pntable['votethailandpoll_tambon_column'] = array(
                                        'id'                => 'tam_id',
                                        'pro_id'            => 'tam_pro_id',
                                        'dis_id'            => 'tam_dis_id',
                                        'name'              => 'tam_name',
                                        'latitude'          => 'tam_latitude',
                                        'longitude'         => 'tam_longitude'
    );
    $pntable['votethailandpoll_tambon_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votethailandpoll_tambon_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_tambon_column'], 'tam_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_tambon_column_def']);

    $pntable['votethailandpoll_tambon_column_idx'] = array(
                                                          'idx_tam_pro_id' => 'pro_id',
                                                          'idx_tam_dis_id' => 'dis_id'
    );

    ////////////////////////////////////////////
    //Village table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_village'] = DBUtil::getLimitedTablename('votethailandpoll_village');
    $pntable['votethailandpoll_village_column'] = array(
                                        'id'                => 'vil_id',
                                        'pro_id'            => 'vil_pro_id',
                                        'dis_id'            => 'vil_dis_id',
                                        'tam_id'            => 'vil_tam_id',
                                        'moo'               => 'vil_moo',
                                        'name'              => 'vil_name',
                                        'latitude'          => 'vil_latitude',
                                        'longitude'         => 'vil_longitude'
    );
    $pntable['votethailandpoll_village_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'moo'               => 'INT(11) NOTNULL',
                                        'name'              => 'varchar(255)',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)'
    );
    $pntable['votethailandpoll_village_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_village_column'], 'vil_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_village_column_def']);

    $pntable['votethailandpoll_village_column_idx'] = array(
                                                          'idx_vil_pro_id' => 'pro_id',
                                                          'idx_vil_dis_id' => 'dis_id',
                                                          'idx_vil_tam_id' => 'tam_id',
                                                          'idx_vil_moo'   => 'moo'
    );

    ////////////////////////////////////////////
    //Party table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_party'] = DBUtil::getLimitedTablename('votethailandpoll_party');
    $pntable['votethailandpoll_party_column'] = array(
                                        'id'                => 'par_id',
                                        'name'              => 'par_name'
    );
    $pntable['votethailandpoll_party_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'varchar(255)'
    );
    $pntable['votethailandpoll_party_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_party_column'], 'par_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_party_column_def']);


    ////////////////////////////////////////////
    //House no. table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_house_no'] = DBUtil::getLimitedTablename('votethailandpoll_house_no');
    $pntable['votethailandpoll_house_no_column'] = array(
                                        'id'                => 'hou_id',
                                        'pro_id'            => 'hou_pro_id',
                                        'dis_id'            => 'hou_dis_id',
                                        'tam_id'            => 'hou_tam_id',
                                        'vil_id'            => 'hou_vil_id',
                                        'vil_moo'           => 'hou_vil_moo',
                                        'no'                => 'hou_no',
                                        'unit'              => 'hou_unit',
                                        'trok'              => 'hou_trok',
                                        'soi'               => 'hou_soi',
                                        'road'              => 'hou_road',
                                        'zipcode'           => 'hou_zipcode',
                                        'latitude'          => 'hou_latitude',
                                        'longitude'         => 'hou_longitude',
                                        'amount_person'     => 'hou_amount_person'

    );
    $pntable['votethailandpoll_house_no_column_def'] = array(
                                        'id'                => 'BIGINT(255) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'vil_id'            => 'INT(11) NOTNULL',
                                        'vil_moo'           => 'INT(11) NOTNULL',
                                        'no'                => 'varchar(50)',
                                        'unit'              => 'INT(11) NOTNULL',
                                        'trok'              => 'INT(11) ',
                                        'soi'               => 'VARCHAR(255)',
                                        'road'              => 'VARCHAR(255)',
                                        'zipcode'           => 'INT(11) ',
                                        'latitude'          => 'varchar(255)',
                                        'longitude'         => 'varchar(255)',
                                        'amount_person'     => 'INT(11) NOTNULL DEFAULT 0'
    );
    $pntable['votethailandpoll_house_no_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_house_no_column'], 'hou_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_house_no_column_def']);

    $pntable['votethailandpoll_house_no_column_idx'] = array(
                                                           'idx_hou_pro_id' => 'pro_id',
                                                           'idx_hou_dis_id' => 'dis_id',
                                                           'idx_hou_tam_id' => 'tam_id',
                                                           'idx_hou_id'     => 'vil_id',
                                                           'idx_hou_moo'    => 'vil_moo',
    );

    ////////////////////////////////////////////
    //Village table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_villagepoll'] = DBUtil::getLimitedTablename('votethailandpoll_villagepoll');
    $pntable['votethailandpoll_villagepoll_column'] = array(
                                        'id'                => 'pol_id',
                                        'pro_id'            => 'pol_pro_id',
                                        'dis_id'            => 'pol_dis_id',
                                        'tam_id'            => 'pol_tam_id',
                                        'vil_id'            => 'pol_vil_id',
                                        'house_no_id'       => 'pol_house_no_id',
                                        'par_id'            => 'pol_par_id',
                                        'status'            => 'pol_status',
                                        'comment'           => 'pol_comment',
    );
    $pntable['votethailandpoll_villagepoll_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',   
                                        'dis_id'            => 'INT(11) NOTNULL',  
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'vil_id'            => 'INT(11) NOTNULL',
                                        'house_no_id'       => 'INT(11) NOTNULL',
                                        'par_id'            => 'INT(11) NOTNULL',
                                        'status'            => 'INT(11) NOTNULL',
                                        'comment'           => 'TEXT',
    );
    $pntable['votethailandpoll_villagepoll_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_villagepoll_column'], 'pol_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_villagepoll_column_def']);

    $pntable['votethailandpoll_villagepoll_column_idx'] = array(
                                                          'idx_pol_pro_id'   => 'pro_id',
                                                          'idx_pol_dis_id'   => 'dis_id',
                                                          'idx_pol_tam_id'   => 'tam_id',
                                                          'idx_pol_vil_id'   => 'vil_id',
                                                          'idx_pol_par_id'   => 'par_id',

    );
    
    ////////////////////////////////////////////
    //Person table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_person'] = DBUtil::getLimitedTablename('votethailandpoll_person');
    $pntable['votethailandpoll_person_column'] = array(
                                        'id'                => 'per_id',
                                        'pro_id'            => 'per_pro_id',
                                        'dis_id'            => 'per_dis_id',
                                        'tam_id'            => 'per_tam_id',
                                        'vil_id'            => 'per_vil_id',
                                        'vil_moo'           => 'per_vil_moo',
                                        'hou_id'            => 'per_hou_id',
                                        'gen_id'            => 'per_gen_id',
                                        'pid'               => 'per_pid',
                                        'firstname'         => 'per_firstname',
                                        'lastname'          => 'per_lastname',
                                        'telephone'         => 'per_telephone',
                                        'mobilephone'       => 'per_mobilephone',
                                        'birthdate'         => 'per_birthdate'
    );
    $pntable['votethailandpoll_person_column_def'] = array(
                                        'id'                => 'BIGINT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'pro_id'            => 'INT(11) NOTNULL',
                                        'dis_id'            => 'INT(11) NOTNULL',
                                        'tam_id'            => 'INT(11) NOTNULL',
                                        'vil_id'            => 'INT(11) NOTNULL',
                                        'vil_moo'           => 'INT(11) NOTNULL',
                                        'hou_id'            => 'INT(11) NOTNULL',
                                        'gen_id'            => 'INT(11) NOTNULL',
                                        'pid'               => 'VARCHAR(255)',
                                        'firstname'         => 'VARCHAR(255)',
                                        'lastname'          => 'VARCHAR(255)',
                                        'telephone'         => 'VARCHAR(255)',
                                        'mobilephone'       => 'VARCHAR(255)',
                                        'birthdate'         => 'DATE'
    );
    $pntable['votethailandpoll_person_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_person_column'], 'per_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_person_column_def']);

    $pntable['votethailandpoll_person_column_idx'] = array(
                                                          'idx_per_pro_id'     => 'pro_id',
                                                          'idx_per_dis_id'     => 'dis_id',
                                                          'idx_per_tam_id'     => 'tam_id',
                                                          'idx_per_vil_id'     => 'vil_id',
                                                          'idx_per_vil_moo'    => 'vil_moo',
                                                          'idx_per_hou_id'     => 'hou_id',
                                                          'idx_per_gen_id'     => 'gen_id',
                                                          'idx_per_pid'        => 'pid'
    );


    ////////////////////////////////////////////
    //Gender table
    ////////////////////////////////////////////
    $pntable['votethailandpoll_gender'] = DBUtil::getLimitedTablename('votethailandpoll_gender');
    $pntable['votethailandpoll_gender_column'] = array(
                                        'id'                => 'gen_id',
                                        'name'              => 'gen_name'
    );
    $pntable['votethailandpoll_gender_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'varchar(255)'
    );
    $pntable['votethailandpoll_gender_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['votethailandpoll_gender_column'], 'gen_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['votethailandpoll_gender_column_def']);



    return $pntable;
}